<template>
  <div>
    <div v-for="(selection, index) in selections" :key="index">
      <div class="selectionWrapper">
        <div class="colorBlock"></div>
        <div class="selectionTitle">{{selection.title}}</div>
        <div class="inline-block small-left-space edit-btn el-icon-edit hover-color" @click="edit(selection)"></div>
        <div class="selectionItemWrapper">
          <div v-for="(option, index) in selection.options" class="selectionItem">
            选项{{index + 1}}：<span>{{option.name}}</span></div>
        </div>
        <div class="radioWrapper">
          <el-radio v-model="selectedOption" :label="selection.id" @change="handleSelectionChange(selectedOption)">
            {{""}}
          </el-radio>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SelectionList',
  model: {
    prop: 'checked',
    event: 'change'
  },
  props: ['checked', 'selections'],
  watch: {
    checked: function () {
      this.selectedOption = this.checked
    }
  },
  data() {
    return {
      selectedOption: ''
    }
  },
  methods: {
    handleSelectionChange(selectedOption) {
      this.$emit("change", selectedOption)
    },
    edit(selection) {
      this.$emit("edit", selection)
    }
  },
  created() {
    this.selectedOption = this.checked
  }
}
</script>

<style scoped>
.selectionWrapper {
  background-color: #F0F8F8;
  height: 80px;
  overflow: auto;
  margin-bottom: 10px;
  position: relative;
}

/** 设置宽度 **/
.selectionWrapper::-webkit-scrollbar {
  width: 4px;
}

.colorBlock {
  background-color: #2DB7A0;
  width: 6px;
  height: 20px;
  position: absolute;
  top: 10px;
  left: 10px;
}

.selectionTitle {
  display: inline-block;
  height: 20px;
  position: absolute;
  top: 10px;
  left: 20px;
  font-weight: bold;
  line-height: 20px;
}

.selectionItemWrapper {
  position: absolute;
  left: 10px;
  bottom: 10px;
  height: 20px;
}

.selectionItem {
  line-height: 20px;
  display: inline-block;
  margin-right: 10px;
  width: fit-content;
}

.radioWrapper {
  position: absolute;
  right: 10px;
  top: 30px;
}

.inline-block {
  display: inline-block;
}

.small-left-space {
  margin-left: 5px;
}

.hover-color:hover {
  color: #2DB7A0;
}

.edit-btn {
  position: absolute;
  height: 20px;
  line-height: 20px;
  top: 10px;
  right: 20px;
  cursor: pointer;
  color: black;
}
</style>
